<%--
  Created by IntelliJ IDEA.
  User: wwh
  Date: 2017/9/9
  Time: 9:22
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>企业端应聘人员信息</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    <link rel="stylesheet" type="text/css" href="../../static/common/layui/css/layui.css" media="all">
    <link rel="stylesheet" type="text/css" href="../../static/common/global.css" media="all">
</head>
<body>
<div class="admin-main">
    <blockquote class="layui-elem-quote"></blockquote>
    <fieldset class="layui-elem-field">
        <legend>应聘列表</legend>
        <div class="layui-form">
            <table class="layui-table">
                <thead>
                <tr>
                    <th>学校</th>
                    <th>学院</th>
                    <th>专业</th>
                    <th>班级</th>
                    <th>姓名</th>
                    <th>性别</th>
                    <th>岗位</th>
                    <th>简历</th>
                    <th>状态</th>
                    <th>操作</th>
                </tr>
                </thead>
                <tbody id="content"></tbody>
            </table>
        </div>
    </fieldset>
    <div class="admin-table-page">
        <div id="paged" class="page"></div>
    </div>
</div>
<script type="text/html" id="tpl">
    {{# layui.each(d.data,function(index,item){ }}
    <tr>
        <td>{{ item.studentInfoDetail.university.name || "-" }}</td>
        <td>{{ item.studentInfoDetail.school.name || "-" }}</td>
        <td>{{ item.studentInfoDetail.major.name || "-" }}</td>
        <td>{{ item.studentInfoDetail.clazz.name || "-" }}</td>
        <td>{{ item.studentInfoDetail.user.realname || "-" }}</td>
        <td>
            {{# if(item.studentInfoDetail.user.sex == 1){ }}
            男
            {{# } }}
            {{# if(item.studentInfoDetail.user.sex == 2){ }}
            女
            {{# } }}
            {{# if(item.studentInfoDetail.user.sex != 2&&item.studentInfoDetail.user.sex != 1){ }}
            -
            {{# } }}


        </td>
        <td>{{ item.positiontype.typename || "-" }}</td>
        <td>
            {{# if(item.cv.filename){ }}
            <a href="javascript:;" target="_blank" data-id="{{item.cv.id}}" data-opt="cvShow">{{ item.cv.filename.split('/')[item.cv.filename.split('/').length-1]}}</a>
            <%--<a href="javascript:;" target="_blank" data-opt="cvShow" data-id="{{item.cv.id}}">{{ item.cv.filename.split('/')[item.cv.filename.split('/').length-1]}}</a>--%>
            {{# } }}
            {{# if(item.cv.filename == null){ }}
            {{# } }}
        </td>
        <td>
            {{# if(item.jobApply.status == 1){ }}
            应聘中
            {{# } }}
            {{# if(item.jobApply.status == 2){ }}
            被拒绝
            {{# } }}
            {{# if(item.jobApply.status == 3){ }}
            已录用
            {{# } }}
        </td>
        <td>
            <%--<a href="javascript:;" target="_blank" data-id="{{item.jobApply.id}}" data-opt="details" class="layui-btn layui-btn-normal layui-btn-mini">详情</a>--%>
            {{# if(item.jobApply.status == 1){ }}
            <a href="javascript:;" target="_self" data-id="{{item.jobApply.id}}" data-opt="refuse" class="layui-btn layui-btn-danger layui-btn-mini">拒绝</a>
            <a href="javascript:;" target="_self" data-id="{{item.jobApply.id}}" data-opt="accept" class="layui-btn layui-btn-mini">录用</a>
            {{# };}}
        </td>
    </tr>
    {{# }); }}
</script>
<script type="text/javascript" src="../../static/common/layui/layui.js"></script>
<script src="../../static/common/axios.min.js"></script>
<script src="../../static/common/vue.min.js"></script>
<script>
    var managerId = ${sessionScope.currentUser.getId()};
    var org = {};
    console.log(managerId);
    // 根据managerId获得企业信息
    axios.get('/orginfo/findByManagerId/'+managerId)
        .then(function (response) {
            console.log(response);
            org = response.data.data.orgInfo;
        })
        .catch(function (msg) {
            console.log(msg);
        })
</script>
<script>
    layui.config({
        base: '../../static/js/layuiModulesEX/'
    });
    layui.use(['paging','laytpl','form'],function () {
        var $ = layui.jquery,
            paging = layui.paging(),
            layer = layui.layer,
            laytpl = layui.laytpl,
            form = layui.form;

        paging.init({
            url:'/jobApply/findByCondition2',
            elem:"#content",
            params:{
                employerid:org.id
            },
            contentType : "application/json; charset=utf-8",
            type: 'POST',
            tempElem: '#tpl', //模块容器
            pageConfig: { //分页参数配置
                elem: 'paged', //分页容器
                pageSize:10 //分页大小
            },
            success:function () {
//                alert('渲染成功');
            },
            fail:function (msg) {
//                alert('获取数据失败');
            },
            complate:function () {
//                alert("处理完成");
                /**
                 * 绑定操作（招聘信息查看/用人单位信息查看）
                 */
                $('#content').children('tr').each(function () {
                    var $CV = $(this).children('td:nth-child(8)');
                    var $that = $(this).children('td:last-child');
                    var id = $that.children('a[data-opt=refuse]').data('id');
                    var CV_ID = $CV.children('a[data-opt=cvShow]').data('id');
                    console.log(CV_ID);
                    /**
                     * 拒绝按钮
                     */
                    $that.children('a[data-opt = refuse]').on('click',function () {
                        console.log("拒绝");
                        axios.get('/jobApply/findOneById/'+id)
                            .then(function (response) {
                                console.log(response);
                                var jobApply = response.data.data;
                                layer.confirm("确认拒绝吗？",function (index) {
                                    jobApply.status = 2;
                                    axios.post('/jobApply/editById',jobApply)
                                        .then(function (res) {
                                            console.log(res);
                                            if(res.data.success){
                                                top.layer.msg("已拒之门外",{icon:1,time:1000});
                                                layer.close(index);
                                                paging.get();
                                            }
                                        })
                                        .catch(function (msg) {
                                            console.log(msg);
                                        })
                                });
                            })
                            .catch(function (msg) {
                                console.log(msg);
                            })
                    });
                    /**
                     * 录用按钮
                     */
                    $that.children('a[data-opt=accept]').on('click',function () {
                         console.log("接受");
                        axios.get('/jobApply/findOneById/'+id)
                            .then(function (response) {
                                console.log(response);
                                var jobApply = response.data.data;
                                layer.confirm("确认录用吗？",function (index) {
                                    jobApply.status = 3;
                                    axios.post('/jobApply/editById',jobApply)
                                        .then(function (res) {
                                            console.log(res);
                                            if(res.data.success){
                                                top.layer.msg("录用成功",{icon:1,time:1000});
                                                layer.close(index);
                                                paging.get();
                                            }
                                        })
                                        .catch(function (msg) {
                                            console.log(msg);
                                        })
                                });
                            })
                            .catch(function (msg) {
                                console.log(msg);
                            })
                    });

                    /**
                     * 简历的在线预览
                     */
                    $CV.children('a[data-opt=cvShow]').on('click',function () {
                        axios.get('/cv/findOneById/'+CV_ID)
                            .then(function (response) {
                                console.log(response.data.data);
                                var url = '/common/pdfHelper?file='+'/static/upload'+response.data.data.filename;
//                                var url = '/static/upload'+response.data.data.filename;
                                window.open(url);
                            })
//                        axios.get('/cv/findOneById/'+CV_ID)
//                            .then(function (response) {
//                                console.log(response.data.data);
//                                var url = '/static/upload'+response.data.data.filename;
//                                console.log(url);
//                                $.get('/common/pdfHelper?file=/static/upload/test.pdf', null, function (html) {
//                                    layer.open({
//                                        type: 1,
//                                        title: "简历预览",
//                                        area: ['600px','600px'],
//                                        content: html
//                                        , success: function (layero, index) {
//                                        }
//                                        , end: function () {
//                                        }
//                                    });
//                                });
//                            })
//                            .catch(function (msg) {
//                                console.log(msg);
//                            });
                    });
                });
            }
        });
    });
</script>
</body>
</html>
